package com.yqy.ssm.controller;

import com.github.pagehelper.PageInfo;
import com.yqy.ssm.pojo.Employee;
import com.yqy.ssm.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;


@Controller
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;

    @GetMapping("/employee")
    public String getAllEmployee(Model model){
        //查询所有员工信息
        List<Employee> allEmployees=employeeService.getAllEmployees();
        //将所有信息共享到请求域
        model.addAttribute("allEmployees",allEmployees);
        //跳转到员工列表页面
        return "employee_list";
    }

    @GetMapping("/employee/page/{pageNum}")
    public String getEmployeePage(@PathVariable("pageNum") Integer pageNum, Model model){
        //获取员工的分页信息
        PageInfo<Employee> page = employeeService.getEmployeePage(pageNum);
        //将分页数据共享到请求域中
        model.addAttribute("page", page);
        //跳转到employee_list.html
        return "employee_page";
    }
}
